<template>
  <nuxt />
</template>

<script>
import { mapActions } from 'vuex'
export default {
  data () {
    return {
      authToken: route.query.token
    }
  },
  created () {
    this.needAuth()
  },
  methods: {
    ...mapActions({
      openAuthLogin: 'user/openAuthLogin',
      getUserInfo: 'user/getUserInfo'
    }),
    needAuth () {
      if (this.authToken) {
        toast.loading('身份验证中...')
        this.openAuthLogin({ token: this.authToken })
          .then(() => {
            this.getUserInfo()
            toast('授权登录成功')
            router.push('/home')
          })
          .catch(({ msg }) => {
            toast(msg)
          })
      } else {
        router.push('/home')
      }
    }
  }
}
</script>
